﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ChatLib;
using System.Collections;

namespace Chat
{
    public partial class FormTasks : Form
    {
        public FormTasks()
        {
            InitializeComponent();
            Refresh();
        }

        private void btnComplete_Click(object sender, EventArgs e)
        {
            CompleteTask(listTasks.SelectedItem.ToString());
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void listTasks_DoubleClick(object sender, EventArgs e)
        {
            CompleteTask(listTasks.SelectedItem.ToString());
        }

        void CompleteTask(string task)
        {
            Global.server.CompleteTask(Global.username, task);
            Refresh();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Refresh();
        }

        private void Refresh()
        {
            ArrayList tasks = Global.server.GetTasks(Global.username);
            listTasks.Items.Clear();

            foreach (object o in tasks)
            {
                listTasks.Items.Add(o.ToString());
            }
        }

    }
}
